// pages/accordion/accordion.js
let app = getApp();
import util from '../../../utils/util.js';
Page({
  data: {
    orderinfo:'',
    imagelist:[],
    repairimages:[],
    total:0,
    isHasPics:false
  },
  

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "详情"
    });

    let data = JSON.parse(options.data);
    console.log(data);
    var list_pic = [];
    var _repairimages = []
    
    var total = 0;
    var items = data.items
    for (var index in items)
    {
      var item = items[index];
      var price = parseFloat(item.price);
      var num = parseInt(item.num);
      var workhourpay = item.workhourpay == '' ? 0 : parseFloat(item.workhourpay);

      total = total+(price + workhourpay)*num;
    }

    if (data.pics != 'null'){
      var arrPics = data.pics.split(",");
      for (var url in arrPics) {
        if (arrPics[url].length > 1) {
          var _url = "https://www.autorepairehelper.cn/file/pic/" + arrPics[url] + ".png";
          _repairimages.push(_url);
        }
      }
    }



    if (data.iscommented ==1)
    {
    if(data.comemnt)
    {
      var pic= data.comemnt.pics;
      if (pic.length>1){
        url = "https://www.autorepairehelper.cn/file/pic/" + pic + ".png";
        list_pic.push(url);
      }
    }
    }
    
    this.setData({
      orderinfo: data,
      imagelist: list_pic,
      total:total,
      repairimages: _repairimages,
      isHasPics: _repairimages.length>0
    });
  },

  formSubmit(event) {
    let data = JSON.stringify(this.data.orderinfo);

    wx.navigateTo({
      url: '../addcomment/addcomment?data=' + data,
    });
  },

  delSubmit(event){
    var url = app.globalData.SERVER + 'comment/del';

    

    util.request(url, 'POST', {
      id: this.data.orderinfo.comemnt._id,
      shopid: this.data.orderinfo.shop._id,
      repid: this.data.orderinfo._id,
      
    }).then(res => {
      util.showToast('成功', 'error', 2500);
    }).catch(err => {
      if (err.data.code === 1) {
        console.log(err.data.ret);
        setTimeout(function () {
          wx.navigateBack({
            delta: -1
          });
        }, 1000) //延迟时间 这里是1秒
        var num = 1;
      } else {
        self.setData({
          siteInfo: err.data.site_info
        });
      }


    });
  },

  
})